
//引入http模块
var http = require('http')

var url = require('url')

var EJS = require('ejs')

http.createServer(function (req,res) {

    res.writeHead(200,{"Content-Type":"text/html;charset=utf-8"})

    //login和register的功能
    var pathName = url.parse(req.url).pathname

    if (pathName == '/login'){
        //将数据库数据渲染到模板上面
        EJS.renderFile('./static/login.ejs',{msg:'2222',list:['222','333','4444']},function (err,data) {
            if (err) {
                console.log('读取文件失败'+err)
            }else{
                console.log(data)
                res.end(data)
            }
        })
    }else if (pathName == '/register') {
        res.end('register')
    }else {
        res.end('other')
    }

}).listen(8008)